function reportCoverSummary(fid,reptitle,content,abstract)
%
%% reportCover(fid,reptitle,content,abstract)
% 
% This function creates the cover a new report tex file 
%
%% Inputs
% fid           Existing file identifier 
% reptitle      String or single cell with report title 
% content       Structure or cell that will be assigned to author tag
% abstract      (optional) Structure or cell that will be assigned to abstract tag
% 
%% Note: ends with maketitle, file remains open 
%  Alejandro Justiniano Sep 5 2012 
% ========================================================================

%% 1. Open document and set environment 
fprintf(fid, '\\documentclass[12pt]{article} \n');
fprintf(fid, '\\usepackage{rotating} \n');
fprintf(fid, '\\usepackage{lscape} \n');
fprintf(fid, '\\usepackage{longtable} \n');
fprintf(fid, '\\usepackage{amsmath}  \n');
fprintf(fid, '\\usepackage{vmargin}  \n');
fprintf(fid, '\\usepackage{setspace}  \n');
fprintf(fid,'\\usepackage{graphicx} \n');
fprintf(fid,'\\usepackage{pdfpages} \n');

% fprintf(fid,'\\usepackage[dvipsnames,usenames]{color} \n');
fprintf(fid,'\\usepackage[pdftex,pdfstartview=Fit,pdfpagelayout=SinglePage,bookmarksopen,');
bookmarkslevel = 1;
fprintf(fid,'bookmarksopenlevel=%.0f,colorlinks,linkcolor=MyDarkBlue,',bookmarkslevel);
fprintf(fid,'citecolor=MyDarkBlue,urlcolor=MyDarkBlue,filecolor=MyDarkBlue,');
fprintf(fid,'naturalnames]{hyperref}\n');
fprintf(fid,'\\setlength{\\oddsidemargin}{0.0in}\n');
fprintf(fid,'\\setlength{\\evensidemargin}{0.0in}\n');
fprintf(fid,'\\setlength{\\topmargin}{0cm}\n');
fprintf(fid,'\\setlength{\\textheight}{10.3in}\n');
fprintf(fid,'\\setlength{\\textwidth}{7.5in}\n');
fprintf(fid,'\\setlength{\\hoffset}{0.0in}\n');
fprintf(fid,'\\setlength{\\headheight}{12.0pt}\n');
fprintf(fid,'\\setlength{\\headsep}{8.0pt} \n');
fprintf(fid,'\\setlength{\\footskip}{0.1in} \n');
fprintf(fid,'\\setcounter{section}{-1} \n');
fprintf(fid,'\\addtocounter{section}{1} \n');


%% 2. Begin document and write title 
fprintf(fid, '\\begin{document} \n');
fprintf(fid, ['\\title{',char(reptitle),'} \n']);
fprintf(fid, '\\bigskip \n');

%% 3. Content assigned to Author tag
%% 3.1 if a structure
if isstruct(content)==true
    names=fieldnames(content);
    Ncontent=length(names);
    for ii=1:Ncontent;
        fldnm=char(names(ii));
        str=char(content.(fldnm));
        if ii==1;
            str=strcat('\\author{',str);
        elseif ii==Ncontent
            str=strcat(str,'}');
        end
        if ii < Ncontent
            fprintf(fid, [str,' \\\\ \n']);
        else
            fprintf(fid, [str,' \n']);
        end
    end
else
    %% 3.2 if a cell
    if iscell(content)==true
        content=content(:);
        Ncontent=length(content);
        for ii=1:Ncontent;
            str=char(content(ii,:));
            if ii==1;
                str=strcat('\\author{',str);
            elseif ii==Ncontent
                str=strcat(str,'}');
            end
            if ii < Ncontent
                fprintf(fid, [str,' \\\\ \n']);
            else
                fprintf(fid, [str,' \n']);
            end
        end
    end
end
%% 4. Date
fprintf(fid, '\\bigskip \n');
fprintf(fid, ['\\date{',[datestr(floor(now)),' ',datestr(rem(now,1))],'} \n']);

%% 5. Abstract
if nargin < 4 || isempty(abstract);
    fprintf(fid, '\\maketitle \n');
    fprintf(fid,' \n');
    return
end
clear str;
%% 5.1 If a structure 
if isstruct(abstract)==true
    abstractNames=fieldnames(abstract);
    for ii=1:length(abstractNames);
        fldnm=char(abstractNames(ii));
        str=char(abstract.(fldnm));
        if ii==1;
            str=strcat('\\abstract{',str);
        elseif ii==length(abstractNames)
            str=strcat(str,'}');
        end
        if ii < length(abstractNames);
            fprintf(fid, [str,' \\\\ \n']);
        else
            fprintf(fid, [str,' \n']);            
        end        
    end
else
    %% 5.1 If a cell
    if iscell(abstract)==true
        abstract=abstract(:);
        for ii=1:length(abstract);
            str=char(abstract(ii,:));
            if ii==1;
                str=strcat('\\abstract{',str);
            elseif ii==length(abstract)
                str=strcat(str,'}');
            end
            if ii < length(abstract);
                fprintf(fid, [str,' \\\\ \n']);
            else
                fprintf(fid, [str,' \n']);
            end
        end
    end
end
fprintf(fid, '\\maketitle \n');
fprintf(fid,' \n'); 
